## Compatibility library

import sys
import itertools

# compatibility for python 2.5 for the moment
if sys.version_info < (2, 6):

    #('Jython', 'tags/Release_2_5_0', '6476')
    #if 'Jython' in sys.subversion:

    def izip_longest(*args, **kwds):
        # izip_longest('ABCD', 'xy', fillvalue='-') --> Ax By C- D-
        fillvalue = kwds.get('fillvalue')
        def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
            yield counter()         # yields the fillvalue, or raises IndexError
        fillers = itertools.repeat(fillvalue)
        iters = [itertools.chain(it, sentinel(), fillers) for it in args]
        try:
            for tup in itertools.izip(*iters):
                yield tup
        except IndexError:
            pass

    #print 'Running in python 2.5 compat mode'

elif sys.version_info < (2, 5):

    raise RuntimeError("We need Python 2.5 or newer to run (but less than 3.0)")
